* ---------------------------------------------------------------------------- *
* BUYERS' SOURCING STRATEGIES AND SUPPLIERS' MARKUPS IN BANGLADESHI GARMENTS
* Cajal-Grossi, J., Macchiavello, R. and Noguera, G.
* 
* REPLICATION CODE 
* This version: January 24, 2023
* ---------------------------------------------------------------------------- *

clear all
set more off
set type double, perm
set seed 10001

* ---------------------------------- *
* SECTION 1: Packages				 *
* ---------------------------------- *

program packages

    local ssc_packages "distinct estout reghdfe egenmore binscatter coefplot ftools ivreg2 ivreghdfe ranktest winsor2 listtex"

    if !missing("`ssc_packages'") {
        foreach pkg in "`ssc_packages'" {

            capture which `pkg'
            if _rc == 111 {                 
               dis "Installing `pkg'"
                ssc install `pkg', replace
               }
        }
    }

end

packages

* ---------------------------------- *
* SECTION 2: Paths					 *
* ---------------------------------- *

global directory =  "D:\Dropbox\Research\Buyer Markups\08. Accepted Submission\Replication"
* user changes the directory to a path of their own

global code = "${directory}\1_Code"
cap mkdir "${code}" // 0_Main.do is stored here 
global floats = "${directory}\1_Code\Floats"
cap mkdir "${floats}" 

global data = "${directory}\2_Data"
cap mkdir "${data}"
global source_data = "${data}\2_1_Source_Data"
cap mkdir "${source_data}"
global generated_data = "${data}\2_2_Generated_Data"
cap mkdir "${generated_data}"
global boot = "${generated_data}\Bootstrap"
cap mkdir "${boot}"

global output = "${directory}\3_Output"
cap mkdir "${output}"
cap rmdir "${output}\3_1_Generated_Data"	
cap rmdir "${output}\3_2_Tables"
cap rmdir "${output}\3_3_Figures"
global replicated_data = "${output}\3_1_Generated_Data"
cap mkdir "${replicated_data}"
global tables = "${output}\3_2_Tables"
cap mkdir "${tables}"
global figures = "${output}\3_3_Figures"
cap mkdir "${figures}"

cd "${directory}"

* ---------------------------------- *
* SECTION 3: Analysis				 *
* ---------------------------------- *

* ----------------------- *
* 	   Elasticities       *
* ----------------------- *

do "${code}\Bootstrap_Elasticities.do"
capture log close

do "${code}\Bootstrap_First_Stages.do"
capture log close

do "${code}\First_Stages_Stats.do"
capture log close

* ----------------------- *
* 	  Labor Analysis      *
* ----------------------- *

do "${code}\Labor_Data_Analysis.do"
capture log close

* --------------------------- *
* 	   Customs Analysis       *
* --------------------------- *

do "${code}\Customs_Data_Analysis.do"
capture log close

do "${code}\Orbis_Characteristics.do"
capture log close

do "${code}\Customs_Data_Characterization.do"
capture log close

* ----------------------- *
* 	 Global Analysis      *
* ----------------------- *

do "${code}\Global_Sourcing_Analysis.do"
capture log close




